package com.ly.cloud.controller;

import com.ly.cloud.vo.NjSelectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.NjDto;
import com.ly.cloud.service.NjService;
import com.ly.cloud.vo.NjVo;
import com.ly.cloud.web.utils.WebResponse;

import io.swagger.annotations.Api;

import java.util.List;
import java.util.Map;

/**
 * 
 * 年级Controller
 * 
 * @author siqi
 * @date 2018年12月13日
 */
@RestController
@RequestMapping("/nj")
@Api("年级Controller")
public class NjController {

	@Autowired
	public NjService njService;

	/**
	 * 分页查询年级列表
	 * 
	 * @param pageNum
	 *            当前页码
	 * @param pageSize
	 *            每页页数
	 * @param njmc
	 *            年级名称
	 * @return
	 */
	@RequestMapping(value = "/queryNj", method = RequestMethod.GET)
	public WebResponse<PageInfo<NjVo>> queryNj(@RequestParam int pageNum, @RequestParam int pageSize,
			@RequestParam(required = false) String njmc) {
		Page<NjVo> page = njService.queryNj(new Page<NjVo>(pageNum, pageSize), njmc);
		return new WebResponse<PageInfo<NjVo>>().success(PageInfo.toPageInfo(page));
	}

	/**
	 * @author siqi
	 * @date 2018-12-13
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/insertNj", method = RequestMethod.POST)
	public WebResponse<Boolean> insertNj(@RequestBody NjDto njDto) {
		Boolean isInsert = njService.insertNj(njDto);
		return new WebResponse<Boolean>().success(isInsert);
	}


	/**
	 * 修改年级信息
	 * 
	 * @param njDto
	 * @return
	 */
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public WebResponse<Boolean> updateById(@RequestBody NjDto njDto) {
		Boolean isUpdate = njService.updateNj(njDto);
		return new WebResponse<Boolean>().success(isUpdate);
	}


	/**
	* @Description: 查询所有年级
	* @Author:
	* @Date: 2018/12/20
	*/
    @RequestMapping(value = "/findAllNj", method = RequestMethod.GET)
	public WebResponse<List<NjSelectVo>> findAllNj(){
        List<NjSelectVo> allNj = njService.findAllNj();
        return new WebResponse<List<NjSelectVo>>().success(allNj);
    }
}
